<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
<head>
<meta charset="UTF-8">
<title>用户中心-确认提现信息</title>
<jsp:include page="/include/wchat/head.jsp"></jsp:include>

<link type="text/css" rel="stylesheet" href="/v2/wchat/resrc/css/account.css">
</head>
<body>
<div id="header"> <a href="javascript:history.go(-1);" class="backto">返回</a>
  <div class="title-sub">确认提现信息</div>
</div>
<div id="wrap">
  <div class="account-balance">
    <div class="link-touch">
      <ul class="items">
        <li><span class="txt">持卡人</span> <span type="password" class="value">${session.user.realName}</span></li>
        <li><span class="txt">绑定银行卡</span><span type="password" class="value">${bank.bankName } - 尾号 ${bank.formatCardNo}</span></li>
        <li><span class="txt">申请提现金额</span> <span type="password" class="value">￥<fmt:formatNumber value="${param.withdrawMoney}" pattern="#,##0.00#"/></span>
        	<input id="withdrawMoney" type="hidden"value="${param.withdrawMoney }" />
        	<input id="bankId" type="hidden" value="${bank.id }" />
        </li>
      	<li><span class="txt">手续费</span> <span id="withdrawFee" type="password" class="value">￥0.00</span></li>
      	<li><span class="txt">实际到账金额</span> 
      	<span id="realTakeOut" class="light-org">￥0.00</span>，预计
								<span class="light-org">${expectedDate}</span>&nbsp;之内到账（双休日和法定节假日顺延）
      		<span id="realTackOut" type="password" class="value">￥0.00</span>
		    <span>，预计${expectedDate}</span>&nbsp;之内到账（双休日和法定节假日顺延）</span>
      	</li>
      	<li><span class="txt">提现后余额</span> <span id="afterCash" type="password" class="value">￥0.00</span></li>
      	<li><span class="txt">交易密码</span>
	      	<input type="password" id="paypassword" name="paypassword" class="input" placeholder="请输入交易密码" maxlength="16">
      	</li>
      </ul>
      <div id="payPasswordTip" style="color:#FC8026;"></div>
    </div>
    <div class="operate-button"> <a href="javascript:submitForm();" id="submitBt" class="btn">申请提现</a> </div>
    <input type="hidden" id="withdrawFeeRate" value="${FeeRate/100}">
	<input type="hidden" id="minWithdrawFee" value="5.00">
	<input type="hidden" id="withdrawNum" value="${withdrawNum}">
  </div>
</div>

<jsp:include page="/include/wchat/footer.jsp"></jsp:include>
<script type="text/javascript">
var freeWithdrawNum = Number('${freeNum}');//免费提现次数
var withdrawNum = Number($("#withdrawNum").val());//当月已提现次数
var withdrawFeeRate = Number($("#withdrawFeeRate").val());
var minWithdrawFee = Number($("#minWithdrawFee").val());

function calcWithDrawFee(){
    var amount = Number('${param.withdrawMoney }');
    var cash = Number('${usableSum}');
    var withdrawFee = 0;
    if(withdrawNum >= freeWithdrawNum){
        withdrawFee = amount * withdrawFeeRate;
        if(withdrawFee < minWithdrawFee){
            withdrawFee = minWithdrawFee;
        }
    }
    withdrawFee = Math.ceil(withdrawFee*100)/100;
    $("#withdrawFee").html("￥"+Util.numFormat(withdrawFee,2));
    var realTakeOut = (amount-withdrawFee) < 0 ? 0 : (amount-withdrawFee);
    $("#realTakeOut").html("￥"+Util.numFormat(realTakeOut,2));
    $("#afterCash").html("￥"+Util.numFormat(cash-amount,2));
}

function addWithdraw(){
    var payPassword = $("#paypassword").val();
    if(payPassword == null || payPassword == ""){
        $("#payPasswordTip").html('请输入支付密码').show();
        return;
    }
    $.ajax({
        url: environment.basePath+"/addWithdraw.do",
        data:{
            "withdrawMoney":$("#withdrawMoney").val(),
            "bankId" : $("#bankId").val(),
            "payPassword" : payPassword,
        },
        type: "POST",
        dataType: "json",
        beforeSend: function(){},
        success: function(data){
			if(data.result == "success"){
				window.location.href = environment.basePath+"/wchatWithdraw_step3.do";
            }else if(data.result == "交易密码错误"){
                $("#payPasswordTip").html(data.result).show();
                $("#submitBt").attr("href","javascript:submitForm();");
            } else {
            	 $("#payPasswordTip").html(data.result).show();
                $("#submitBt").attr("href","javascript:submitForm();");
            }
        },
        error: function(){
         
        }
    });
}

function submitForm(){
    var submitBt = $("#submitBt");
    submitBt.attr("href","javascript:;");
    $("#payPasswordTip").hide();
    if($("#paypassword").val() == ''){
        $("#payPasswordTip").html('请输入支付密码').show();
        submitBt.attr("href","javascript:submitForm();");
        return;
    }

    addWithdraw();
}

$(function(){
    calcWithDrawFee();
});
</script>

</body>
</html>